<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/background/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/background/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/js/xadmin.js"></script>
</head>
<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>预约用户名
            </label>
            <div class="layui-input-inline">
                <select name="reUid" class="species">
                    <c:forEach items="${users}" var="user" varStatus="row">
                        <option value="${user.uId}">${user.username}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>预约类型
            </label>
            <div class="layui-input-inline">
                <input type="text" name="reType" value="${reType}" readonly="readonly" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>预约时间
            </label>
            <div class="layui-input-inline">
                <input  type="text" id="dnDate" name="reTime" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>预约时长
            </label>
            <div class="layui-input-inline">
                <input type="text" id="className" name="reDuration" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script type="text/javascript">

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#dnDate'
            ,type: 'datetime'
            ,trigger: 'click'
        });
    })

    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);//是一个表单对象
            console.log(data.field);//data.field代表表单中提交的数据
            //发异步，把数据提交给Servlet
            $.ajax({
                type:'POST',
                url:'addReserve',
                data:data.field,
                //等待返回值
                success:function(result){
                    if(result=="SUCCESS"){
                        layer.alert("添加成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新我的 双亲页面 classobjlist.jsp
                            window.parent.location.reload();
                        });
                    }
                    else{
                        layer.alert(result,{title:"添加失败"});
                    }
                }
            });
            return false;
        });
    });

</script>
</body>
</html>